package com.jiayang.hhotel.presenter;

import android.app.AlertDialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.jiayang.hhotel.R;
import com.jiayang.hhotel.bean.ContractListModel;
import com.jiayang.hhotel.ui.ContractActivity;
import com.jiayang.hhotel.util.StringUtil;
import com.jiayang.hhotel.util.ToastUtil;

import java.util.ArrayList;

import cn.droidlover.xdroidmvp.mvp.XPresent;

/**
 * Created by Administrator on 2017/5/26 0026.
 * 合同逻辑类
 */

public class ContractPresenter extends XPresent<ContractActivity> {

    public void asyncLoad() {
        ArrayList<ContractListModel> list = new ArrayList<>();
        list.add(new ContractListModel("11", "11", "11", "11"));
        list.add(new ContractListModel("11", "11", "11", "11"));
        list.add(new ContractListModel("11", "11", "11", "11"));
        list.add(new ContractListModel("11", "11", "11", "11"));
        list.add(new ContractListModel("11", "11", "11", "11"));
        list.add(new ContractListModel("11", "11", "11", "11"));
        list.add(new ContractListModel("11", "11", "11", "11"));
        list.add(new ContractListModel("11", "11", "11", "11"));
        list.add(new ContractListModel("11", "11", "11", "11"));
        getV().setAdapter(list);

    }

        AlertDialog addContractDialog;
        /**
         * 创建续约合同对话框
         * @param context 上下文
         */
    public void createRenewDialog(final Context context){
        final AlertDialog.Builder builder=new AlertDialog.Builder(context);
        View itemView= LayoutInflater.from(context).inflate(R.layout.dialog_renew_contract,null);
        final EditText editText= (EditText) itemView.findViewById(R.id.et_new_num);
        Button enterMine= (Button) itemView.findViewById(R.id.bt_enterMine);
        enterMine.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String num=editText.getText().toString();
                if(!StringUtil.isEmpty(num)){
                    addContractDialog.dismiss();
                }else{
                    ToastUtil.Toast(context.getResources().getString(R.string.please_input_num),context);
                }
            }
        });
        builder.setView(itemView);
        addContractDialog =builder.show();
    }
}
